package top.kaoshanji.p1ch02a;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.StandardOutputStreamLog;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @author kaoshanji
 * ^_^
 * create time 2025/4/22 15:23
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = CDPlayerConfig.class)
public class CDPlayerTest {

    @Rule
    public final StandardOutputStreamLog log = new StandardOutputStreamLog();

    @Autowired
    private MediaPlayer player;

    @Autowired
    private CompactDisc cd;

    /**
     * 代码清单test-p1ch02a-37页a：测试组件扫描能够发现CompactDisc
     */
    @Test
    public void cdShouldNotBeNull() {
        Assert.assertNotNull(cd);
    }

    /**
     * 代码清单test-p1ch02a-42页a：验证自动装配
     * 去掉换行就好了
     */
    @Test
    public void play() {
        player.play();
        Assert.assertEquals("Playing Sgt. Pepper's Lonely Hearts Club Band by The Beatles", log.getLog());

        // Assert.assertEquals("SgtPeppers", log.getLog());
    }

}
